using System;
namespace ch.ethz.ssh2.packets
{
	
	/// <summary> PacketServiceRequest.
	/// 
	/// </summary>
	/// <author>  Christian Plattner
	/// </author>
	/// <version>  2.50, 03/15/10
	/// </version>
	public class PacketServiceRequest
	{
		virtual public byte[] Payload
		{
			get
			{
				if (payload == null)
				{
					TypesWriter tw = new TypesWriter();
					tw.writeByte(Packets.SSH_MSG_SERVICE_REQUEST);
					tw.writeString(serviceName);
					payload = tw.getBytes();
				}
				return payload;
			}
			
		}
		internal byte[] payload;
		
		internal System.String serviceName;
		
		public PacketServiceRequest(System.String serviceName)
		{
			this.serviceName = serviceName;
		}
		
		public PacketServiceRequest(byte[] payload, int off, int len)
		{
			this.payload = new byte[len];
			Array.Copy(payload, off, this.payload, 0, len);
			
			TypesReader tr = new TypesReader(payload, off, len);
			
			int packet_type = tr.readByte();
			
			if (packet_type != Packets.SSH_MSG_SERVICE_REQUEST)
				throw new System.IO.IOException("This is not a SSH_MSG_SERVICE_REQUEST! (" + packet_type + ")");
			
			serviceName = tr.readString();
			
			if (tr.remain() != 0)
				throw new System.IO.IOException("Padding in SSH_MSG_SERVICE_REQUEST packet!");
		}
	}
}